#import "OmChangePasswordWithoutMailVC.h"
#import "OmCommonField0.h"
#import "OmCommonButton0.h"
@interface OmChangePasswordWithoutMailVC ()
@property (nonatomic, strong) OmCommonField0 *previousPasswordField;
@property (nonatomic, strong) OmCommonField0 *currentPasswordField;
@property (nonatomic, strong) OmCommonField0 *checkPasswordField;
@property (nonatomic, strong) OmCommonButton0 *submitButton;
@end
@implementation OmChangePasswordWithoutMailVC
#pragma mark - Event
- (void)onSubmitButtonTap {
    if (![self isDataCorrect]) return;
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"change_pass"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"old_password"] = self.previousPasswordField.text;
    param[@"password"] = self.currentPasswordField.text;
    param[@"repassword"] = self.checkPasswordField.text;
    [CYNET POST:url parameters:param responseCache:^(id responseObject) {
    } success:^(id responseObject) {
        [MBProgressHUD showSuccessMessage:ASLocalizedString(@"修改成功")];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSString *error) {
    } hasCache:NO];
}
- (BOOL)isDataCorrect {
    if (self.previousPasswordField.text.length * self.currentPasswordField.text.length * self.checkPasswordField.text.length <= 0) {
        [MBProgressHUD showInfoMessage:ASLocalizedString(@"请完整输入信息")];
        return NO;
    } else if (![self.currentPasswordField.text isEqualToString:self.checkPasswordField.text]) {
        [MBProgressHUD showInfoMessage:ASLocalizedString(@"密码验证不正确")];
        return NO;
    }
    return YES;
}
#pragma mark - ConstructionScript
- (void)configSelf {
    [self setHiddenForTabBar:YES navigationBar:NO];
    self.title = ASLocalizedString(@"修改密码");
}
- (void)allocateComponents {
    self.previousPasswordField = [[OmCommonField0 alloc] initWithPlaceHolder:ASLocalizedString(@"请输入原密码")];
    [self.view addSubview:self.previousPasswordField];
    self.currentPasswordField = [[OmCommonField0 alloc] initWithPlaceHolder:ASLocalizedString(@"请输入新密码")];
    [self.view addSubview:self.currentPasswordField];
    self.checkPasswordField = [[OmCommonField0 alloc] initWithPlaceHolder:ASLocalizedString(@"请再次确认新密码")];
    [self.view addSubview:self.checkPasswordField];
    self.submitButton = (OmCommonButton0 *)[[OmCommonButton0 alloc] initWithTitle:ASLocalizedString(@"完成")]
    .fp_addTargetActionForControlEvents(self, @selector(onSubmitButtonTap), UIControlEventTouchUpInside);
    [self.view addSubview:self.submitButton];
}
- (void)layoutComponents {
    [self.previousPasswordField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.view).offset(RPX(33));
    }];
    [self.currentPasswordField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.previousPasswordField.mas_bottom).offset(RPX(28));
    }];
    [self.checkPasswordField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.currentPasswordField.mas_bottom).offset(RPX(28));
    }];
    [self.submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.checkPasswordField.mas_bottom).offset(RPX(40));
    }];
}
@end
